<script>
	export default {
		globalData: {  
			// pic_address: 'https://www.hbxtwl.com/as230/',
			// app_address: 'https://www.hbxtwl.com/as230/pbapi',//正式版本
			// fileService:'pbfile2',//正式版本`
			pic_address: 'https://www.hbxtwl.com/as176/',
			app_address: 'https://www.hbxtwl.com/as176/pbapi',//测试版本
			
			// pic_address: 'http://47.104.140.185/as185/',
			// app_address: 'http://47.104.140.185/as185/pbapi',//正式版本
			fileService:'',//测试版本
			fontsize:'16px',
			
			// pic_address: 'https://www.shws1942.com/',
			// app_address: 'https://www.shws1942.com/pbapi3',
        }, 
		
		
		//发布正式版本需要修改 App.vue  first.vue manifest.json
		
		onLaunch: function() {
			
			
			uni.hideTabBar()
			var that = this
			// #ifdef APP-PLUS
			uni.getSystemInfo({
				success: (res) => {
					console.log('getSystemInfo',res)
					if (res.platform == "android") {
						that.checkUpdateApp();
					}
				}
			})
			// #endif
			// #ifndef APP-PLUS
			if (uni.canIUse('getUpdateManager')) {
			  const updateManager = uni.getUpdateManager()
			  updateManager.onCheckForUpdate(function (res) {
				if (res.hasUpdate) {
				  updateManager.onUpdateReady(function () {
					  updateManager.applyUpdate()
				  })
				  updateManager.onUpdateFailed(function () {
					uni.showModal({
					  title: '已经有新版本了哟~',
					  content: '新版本已经上线啦~，请您删除当前小程序，重新搜索打开哟~'
					})
				  })
				}
			  })
			}
			// #endif
		},
		

		methods:{
			
			
			/* 检查更新 在线更新 */
			checkUpdateApp(){
				var that = this
				plus.runtime.getProperty(plus.runtime.appid, function(widgetinfo) {
					console.log(widgetinfo)
					//发布更新一定要改
					if (widgetinfo.name == "FCPDA") {
						var injson = `{`
									+`"terminalType":"WeChat",`
									+`"productCode":"SCM",`
									+`"projectCode":"HMS",`
									+`"accountName":"FamilyCity"`
									+`}`
									console.log('saas_APKVersion',injson)
						uni.request({
							url: getApp().globalData.app_address + '?method=saas_APKVersion&parse=json',
							data: injson,
							method: 'POST',
							header: { 'content-type': 'application/x-www-form-urlencoded' },
							success: function(srcData) {
								let data = srcData.data.data;
								console.log('saas_APKVersion',data)
								let version = widgetinfo.version
								let appVersion = data.appversion
								let appName = widgetinfo.name
								let appurl = data.appurl
								let intro = '新版本已经上线啦~'
								if(data && that.$compare(appVersion,version)>0){
									uni.showModal({
										title:"更新提示",
										confirmText:"立即升级",
										content:intro,
										showCancel:false,
										success: (res) => {
											if (res.confirm) {
												uni.showLoading({title:"正在更新",mask:true})
												uni.downloadFile({
													url:appurl,
													success: (download) => {
														if(download.statusCode == 200){
															plus.runtime.install(download.tempFilePath,{
																force:false
															},()=>{
																uni.hideLoading();
																plus.runtime.restart();
															},(err)=>{
																uni.hideLoading();
																uni.showToast({
																	title:"更新失败，将跳转下载页面",
																	icon:"none",
																	duration:2000
																})
															})
															setTimeout(function(){
																plus.runtime.openURL(appurl);
															},2000)
														}
													},
													fail:function(){
														uni.hideLoading();
													}
												})
											}
										
										}
									})
								}
							
							}
						})
					} 
				
				});
				
			},
			
		
		}
	 }
</script>


<style lang="scss">
	@import "./components/iconfont/iconfont.css";
	page {
		min-height: 100%;
		display: flex;
		font-size: 16px;
	}
	
	@media (max-width: 500px) {
		page {
			font-size: 20px;
		}
	}
	
	@media (min-width: 501px) and (max-width: 800px) {
	  page {
	  	font-size: 18px;
	  }
	}
	 
	@media (min-width: 801px) {
	  page {
	  	font-size: 20px;
	  }
	}
</style>
